package org.rmc.demo.cfca;

import com.itextpdf.text.pdf.PdfSignatureAppearance;
import com.itextpdf.text.pdf.security.DigestAlgorithms;
import com.itextpdf.text.pdf.security.MakeSignature;

import java.security.PrivateKey;
import java.security.cert.Certificate;

/**
 * @author ranmc
 * @date 2019-07-18
 */
public class SignInfo {

    /**
     * 签名页码
     */
    private int page;

    private float x1;

    private float y1;

    private float x2;

    private float y2;

    /**
     * 签名详细信息：原因
     */
    private String reason;

    /**
     * 签名详细信息：位置
     */
    private String location;

    /**
     * 摘要类型
     */
    private String da;

    /**
     * 内容
     *  isImage=true 图片路径
     *  isImage=false 显示文字
     */
    private String content;

    /**
     * 签名域名称
     */
    private String fieldName;

    /**
     * 证书链
     */
    private Certificate[] chain;

    /**
     * 私钥
     */
    private PrivateKey pk;

    /**
     * 批准签名
     */
    private int sa;

    /**
     * 表现形式：
     *      仅描述
     *      仅图片
     *      图片和描述
     *      签章者和描述
     */
    private PdfSignatureAppearance.RenderingMode rm;

    /**
     * 支持标准，CMS,CADES
     */
    private MakeSignature.CryptoStandard cs;

    /**
     * 是否是图片
     *  true 图片
     *  false 文字
     */
    private boolean isImage;

    /**
     * 是否是封签
     */
    private boolean facing;

    public int getPage() {
        return page;
    }

    public SignInfo setPage(int page) {
        this.page = page;
        return this;
    }

    public float getX1() {
        return x1;
    }

    public SignInfo setX1(float x1) {
        this.x1 = x1;
        return this;
    }

    public float getY1() {
        return y1;
    }

    public SignInfo setY1(float y1) {
        this.y1 = y1;
        return this;
    }

    public float getX2() {
        return x2;
    }

    public SignInfo setX2(float x2) {
        this.x2 = x2;
        return this;
    }

    public float getY2() {
        return y2;
    }

    public SignInfo setY2(float y2) {
        this.y2 = y2;
        return this;
    }

    public String getReason() {
        return reason;
    }

    public SignInfo setReason(String reason) {
        this.reason = reason;
        return this;
    }

    public String getLocation() {
        return location;
    }

    public SignInfo setLocation(String location) {
        this.location = location;
        return this;
    }

    public String getDa() {
        return da;
    }

    public SignInfo setDa(String da) {
        this.da = da;
        return this;
    }

    public String getContent() {
        return content;
    }

    public SignInfo setContent(String content) {
        this.content = content;
        return this;
    }

    public String getFieldName() {
        return fieldName;
    }

    public SignInfo setFieldName(String fieldName) {
        this.fieldName = fieldName;
        return this;
    }

    public Certificate[] getChain() {
        return chain;
    }

    public SignInfo setChain(Certificate[] chain) {
        this.chain = chain;
        return this;
    }

    public PrivateKey getPk() {
        return pk;
    }

    public SignInfo setPk(PrivateKey pk) {
        this.pk = pk;
        return this;
    }

    public int getSa() {
        return sa;
    }

    public SignInfo setSa(int sa) {
        this.sa = sa;
        return this;
    }

    public PdfSignatureAppearance.RenderingMode getRm() {
        return rm;
    }

    public SignInfo setRm(PdfSignatureAppearance.RenderingMode rm) {
        this.rm = rm;
        return this;
    }

    public MakeSignature.CryptoStandard getCs() {
        return cs;
    }

    public SignInfo setCs(MakeSignature.CryptoStandard cs) {
        this.cs = cs;
        return this;
    }

    public boolean getIsImage() {
        return isImage;
    }

    public SignInfo setIsImage(boolean isImage) {
        this.isImage = isImage;
        return this;
    }

    public boolean getFacing() {
        return facing;
    }

    public SignInfo setFacing(boolean facing) {
        this.facing = facing;
        return this;
    }

    public SignInfo(int page, float x1, float y1, float x2, float y2, String reason, String location, String content, String fieldName, Certificate[] chain, PrivateKey pk, boolean isImage) {
        this.page = page;
        this.x1 = x1;
        this.y1 = y1;
        this.x2 = x2;
        this.y2 = y2;
        this.reason = reason;
        this.location = location;
        this.da = DigestAlgorithms.SHA1;
        this.content = content;
        this.fieldName = fieldName;
        this.chain = chain;
        this.pk = pk;
        this.sa = PdfSignatureAppearance.NOT_CERTIFIED;
        this.cs = MakeSignature.CryptoStandard.CMS;
        this.isImage = isImage;
        this.facing = false;
        if (isImage){
            this.rm = PdfSignatureAppearance.RenderingMode.GRAPHIC;
        } else {
            this.rm = PdfSignatureAppearance.RenderingMode.DESCRIPTION;
        }
    }

    public SignInfo(int page, float x1, float y1, float x2, float y2, String reason, String location, String content, String fieldName, Certificate[] chain, PrivateKey pk, boolean isImage, boolean facing) {
        this.page = page;
        this.x1 = x1;
        this.y1 = y1;
        this.x2 = x2;
        this.y2 = y2;
        this.reason = reason;
        this.location = location;
        this.da = DigestAlgorithms.SHA1;
        this.content = content;
        this.fieldName = fieldName;
        this.chain = chain;
        this.pk = pk;
        this.sa = PdfSignatureAppearance.NOT_CERTIFIED;
        this.cs = MakeSignature.CryptoStandard.CMS;
        this.isImage = isImage;
        this.facing = facing;
        if (isImage){
            this.rm = PdfSignatureAppearance.RenderingMode.GRAPHIC;
        } else {
            this.rm = PdfSignatureAppearance.RenderingMode.DESCRIPTION;
        }
    }
}
